package com.corpgovernment.costcenter.validator;

import com.corpgovernment.api.costcenter.model.CostCenter;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.stereotype.Component;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class ParamValidator {
	private static final String delimiter= "、";

    public String validCostCenterParam(CostCenter costCenter) {
        StringBuilder sb=new StringBuilder("");
	    if (StringUtils.isBlank(costCenter.getCostCenterName())) {
		    sb.append("成本中心名称不能为空、");
	    }
        if(StringUtils.isBlank(costCenter.getCostCenterCode())) {
			sb.append("成本中心编码不能为空、");
		}
	    if (StringUtils.isBlank(costCenter.getCompany())) {
		    sb.append("成本中心所属公司不能为空、");
	    }
	    if (StringUtils.isBlank(costCenter.getCompanyId())) {
		    sb.append("成本中心所属公司id不能为空、");
	    }
	    if (CollectionUtils.isEmpty(costCenter.getDepartments())) {
		    sb.append("成本中心对应的部门不能为空");
	    }
		int length = sb.length();
		if (length != 0 && delimiter .equals(sb.substring(length -1)) ) {
			return sb.substring(0, length - 1);
		}
        return sb.toString();
    }

}
